package yuhao.jdbc;

import java.sql.*;

public class Jdbc5 {
    public static void main(String[] args) throws Exception {

        // 1.注册驱动
        //Class.forName("com.mysql.jdbc.Driver");


        // 2.获取数据库连接
        String url = "jdbc:mysql://127.0.0.1/db6?useSSL=false";
        String username = "root";
        String password = "1234";
        Connection conn = DriverManager.getConnection(url, username, password);
        String name = "zhangsan";
        String psd = "123";

        String sql = "select * from tb_user where username=? and password=?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1,"zhangsan");
        preparedStatement.setString(2,"123");
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            System.out.println("登陆成功");
        } else {
            System.out.println("登录失败");
        }

    }


}

